<%--
  Created by IntelliJ IDEA.
  User: 何亮龙
  Date: 2020/7/28
  Time: 16:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>后台管理员信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">账号名</label>
                    <div class="layui-input-block">
                        <input type="text" name="adminName" placeholder="请输入管理员账号名" autocomplete="off" class="layui-input">
                    </div>
                </div>
               <%-- <div class="layui-inline">
                    <label class="layui-form-label">管理员手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="telphone" placeholder="请输入要搜索的管理员手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>
              <%--  <div class="layui-inline">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>--%>
                <div class="layui-inline">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <select name="adminRole">
                            <option value="" selected="selected"></option>
                            <option value="普通管理员">普通管理员</option>
                            <option value="超级管理员">超级管理员</option>
                            <!-- <option value="2">纠错员</option>
                             <option value="3">采购员</option>
                             <option value="4">推销员</option>
                             <option value="5">运营人员</option>
                             <option value="6">编辑</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin" id="insertManager" data-type="add">添加</button>
            </div>
        <%--   <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.check == true){ }}
                <button class="layui-btn layui-btn-xs">已审核</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                {{#  } }}
            </script>--%>
            <script type="text/html" id="table-useradmin-admin">
               <table id="manager_list" lay-filter="manager_list"></table>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/back/layuiadmin/layui/layui.js"></script>
<script>

    layui.config({
        base: '${pageContext.request.contextPath}/back/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['table','laydate','form'], function(){
        var table = layui.table,
            laydate = layui.laydate,
            form = layui.form,
            $ = layui.$;
        var cols = [[ //表头
            {field: 'adminId', title: '管理员编号', sort: true, width:100, fixed: 'left',templet:'<div>{{d.adminId}}</div>'}
            ,{field: 'adminName', title: '管理员账号名', sort: true, width:120,templet:'<div>{{d.adminName}}</div>'}
            ,{field: 'adminPwd', title: '管理员密码', sort: true, width: 300,templet:'<div>{{d.adminPwd}}</div>'}
            ,{field: 'adminRole', title: '管理员角色', width:200, sort: true,templet:'<div>{{d.adminRole}}</div>'}
            ,{field: 'adminRegTime', title: '管理员注册时间', width:200, sort: true,templet:'<div>{{d.adminRegTime}}</div>'}
            ,{field: '', title: '操作', width: 200,toolbar:"#table-content-list"}
        ]];
        table.render({
            elem: '#manager_list'
            ,url: '${pageContext.request.contextPath}/back/manager' //数据接口
            ,page: true //开启分页
            ,cols: cols
            ,parseData:function(res){
                return {
                    "code": 0, //解析接口状态
                    "msg": "搜索成功", //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.list, //解析数据列表
                };
            }
        });
        table.on("tool(manager_list)",function(obj){
            var data = obj.data;
            var adminId = data.adminId;
            console.log(adminId);
            if(obj.event === 'del'){
                layer.confirm('您确定删除用户编号：'+adminId+'的数据吗？', function(index){
                    //向服务端发送删除指令，在这里可以使用Ajax异步
                    $.ajax({
                        type:'delete'
                        ,url:'/back/deleteManager/' + adminId
                        ,dataType:'json'
                        ,success:function(result) {
                            if (result == true) { //删除成功，刷新当前页表格
                                //删除对应行（tr）的DOM结构，并更新缓存
                                obj.del();
                                layer.close(index);
                            } else if (result == false) { //删除失败
                                layer.alert("删除失败");
                            }
                        }
                    });
                });
                // 修改事件
            }
        });
        form.on('submit(search)',function(data){
            var field = data.field;
            console.log(field);
            layer.msg("正在搜索");
            table.render({
                elem: '#manager_list'
                ,url: '/back/manager' //数据接口
                ,where:field
                ,page: true //开启分页
                ,cols: cols
                ,parseData:function(res){
                    return {
                        "code": 0, //解析接口状态
                        "msg": "", //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.list, //解析数据列表
                    };
                }
            });
        });
        // 弹出添加管理员的模态框
        $(document).on("click","#insertManager",function () {
            // 打开隐藏的增加表单
            index = layer.open({
                type : 1,
                title : "添加管理员",
                area : ['550px', '550px'],
                content : $('#add_from')
            });
            $.ajax({
                type:"post",
                url:'/back/insertMnager',
                success:function (result) {
                    if (result == true) {
                        alert("添加管理员信息成功");
                    }
                },
                error:function () {
                    alert("添加管理员信息失败");
                }
            });
        });
    /*    //事件
        var active = {
           add: function(){
                layer.open({
                    type: 2
                    ,title: '添加管理员'
                    ,content: 'adminform.html'
                    ,area: ['420px', '420px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-back-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段

                            //提交 Ajax 成功后，静态更新表格中的数据
                            //$.ajax({});
                            table.reload('LAY-user-front-submit'); //数据刷新
                            layer.close(index); //关闭弹层
                        });

                        submit.trigger('click');
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });*/
    });
</script>
    <!-- 放置添加元素，默认隐藏 -->
<div id="add_from" style="display:none;width:300px;margin-top: 20px">
        <form class="layui-form" action="${pageContext.request.contextPath}/back/insertMnager" lay-filter="example" id="addManager" enctype="multipart/form-data" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">管理员账号名</label>
        <div class="layui-input-inline">
            <input type="text" name="adminName" lay-verify="required" placeholder="请输入管理员账号名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="adminPwd" lay-verify="adminName" placeholder="请输入设置密码" autocomplete="off" class="layui-input">
        </div>
    </div>
  <%--  <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>--%>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            <select name="adminRole" id="adminRole">
                <option value="普通管理员">普通管理员</option>
                <option value="超级管理员">超级管理员</option>
            </select>
        </div>
    </div>
    <%--<div class="layui-form-item">
        <label class="layui-form-label">审核状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="switch" lay-skin="switch" lay-text="通过|待审核">
        </div>
    </div>--%>
    <div class="layui-form-item layui-hide">
        <input type="submit" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-back-submit" value="确认">
    </div>
     </form>
</div>
</body>
</html>

